package com.spring.student.Test;
import com.spring.student.Dao.CourseManage;
import com.spring.student.Dao.ScoreManage;
import com.spring.student.Dao.UserManage;
import com.spring.student.Dao.UserManageImpl;
import com.spring.student.systemDB.Score;
import com.spring.student.systemDB.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class StudentSystemDB {public static void main(String[] args) {
    ApplicationContext context;
    context = new ClassPathXmlApplicationContext("student_systemDB.xml");
    User user = (User) context.getBean("user");
    UserManage userManage = (UserManageImpl) context.getBean("userManage");
    Score score = (Score) context.getBean("score");
    ScoreManage scoreManage = (ScoreManage) context.getBean("scoreManage");
    CourseManage courseManage = (CourseManage) context.getBean("courseManage");
    user.setNumber("11015");
    user.setPassword("654321");
    user.setIdentity("教师");
    if (userManage.login(user)){
        System.out.println(user.getIdentity()+ "用户登录成功");
        System.out.println("插入20220103001的学生成绩记录");
        score.setNumber("20220103001");
        score.setChinese(110.0);
        score.setMath(101.0);
        score.setEnglish(98.0);
        scoreManage.addScore(score);
        System.out.println("查询所有的学生成绩记录：");
        scoreManage.queryAllScore();
        System.out.println("更新20220102001的数学成绩");
        scoreManage.updateScore("20220102001","math",100.0);
        System.out.println("查询所有的学生参成绩记录：");
        scoreManage.queryAllScore();
    }
    else
        System.out.println(user.getIdentity()+ "账号或密码错误");
    user.setNumber("20220102001");
    user.setPassword("123456");
    user.setIdentity("学生");
    if (userManage.login(user)){
        System.out.println(user.getIdentity()+ "用户登录成功");
        System.out.println("查询该学生的成绩记录:");
        scoreManage.queryScoreByNum("20220102001");
        System.out.println("查询待选课程记录：");
        courseManage.queryCourse();
        try {
            System.out.println("执行选课操作");
            courseManage.selectCourse("20220102001","moive");
        }catch (RuntimeException e){
            System.out.println("异常信息："+ e.getMessage());
            System.out.println("事务执行回滚");
        }
        finally {
            System.out.println("执行选课操作后，查询待选课程记录：");
            courseManage.queryCourse();
        }
    }
    else
        System.out.println(user.getIdentity()+ "用户账号或密码错误");
    ((AbstractApplicationContext)context).close();
}


}
